package General;
import java.util.LinkedList;
import Card.Card;
import java.util.Collections;


public class Deck 
{
	LinkedList<Card> activeCards;
	LinkedList<Card> spentCards;
	Deck(LinkedList<Card> cards)
	{
		super();
		activeCards = cards;
		spentCards=new LinkedList<Card>();
	}//end Card list constructor
	
	public void restock()
	{
		if (activeCards.isEmpty())
		{
			activeCards = spentCards;
			Collections.shuffle(activeCards);
			spentCards = new LinkedList<Card>();
		}//end if
		
		else 
		{
			activeCards.addAll(spentCards);	//move spent cards in case there were cards in both decks
			Collections.shuffle(activeCards);
			spentCards = new LinkedList<Card>();//empty
		}//end else
	
	}//end restock()
	
	Card dealBattle()
	{
		return deal();
	}//end dealBattle()
	
	Card deal()
	{
		if(activeCards.isEmpty()) restock();
		Card activeCard = (Card)activeCards.pop();	//draw a card from activeCards deck
		int i =0;
		while(activeCard ==null){
			i++;
			System.out.println("error, null card found"+i);
			activeCard = (Card)activeCards.pop();
		}
		spentCards.push(activeCard);	//push the spent card into the spent cards stack
		return activeCard;	//
	}//end deal()
}//end class
